//设备
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { getEnterprisePrickPoint } from '@gis/lib/api';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = 'shebei';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getLabel() {
    const label = super.getLabel();
    label.content = `
      <div class="marker_label">
        <p class="marker_label__name">${this.data.subject_name}</p>
      </div>`;
    return label;
  }
  onClick() {}
}

export default class Shebei extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      area_code: area_code,
    };
    const data = await handleCommonRes(getEnterprisePrickPoint, params);
    /*const res = [
        {
          longitude: "104.097858",
          latitude: "30.661199",
          subject_name: "智能设备一",
        },
        {
          longitude: "104.096858",
          latitude: "30.660199",
          subject_name: "餐厅烟感设备",
        },
        {
          longitude: "104.096427",
          latitude: "30.659827",
          subject_name: "智能井盖",
        },
        {
          longitude: "104.096193",
          latitude: "30.659438",
          subject_name: "人脸探头",
        },
        {
          longitude: "104.098942",
          latitude: "30.661007",
          subject_name: "电力监测",
        },
      ];*/
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
